#include<iostream>
#include<string>
#include<vector>
#include<map>
#include <algorithm>    // std::stable_sort
using namespace std;

class Solution {
public:
    // 仿函数控制比较逻辑
    struct Compare
    {
        bool operator() (const pair<string, int>& x, const pair<string, int>& y) const
        {
            return x.second > y.second;
        }
    };

    vector<string> topKFrequent(vector<string>& words, int k) {
        // 统计次数
        map<string, int> coutmp;
        for (auto& e : words) {
            coutmp[e]++;
        }

        vector<pair<string, int>> vt(coutmp.begin(), coutmp.end());
        // 排序
        stable_sort(vt.begin(), vt.end(), Compare());
        // 取前k个
        vector<string> vstr;
        for (int i = 0; i < k; i++) {
            vstr.push_back(vt[i].first);
        }
        return vstr;
    }
};

int main()
{
    return 0;
}
